﻿using Microsoft.AspNetCore.Mvc;
using WCS_Entity.Dto.RcsDto;
using WCS_Entity.Dto;
using WCS_Service.Interface;
using WCS_Service.Services;
using WCS_Entity.Dto.UpperSysDto;

namespace WCS.Controllers
{
    /// <summary>
    /// 上位服务管理接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class UpperSysServiceController : ControllerBase
    {
        private readonly IUpperSysService _upperSysService;
        public UpperSysServiceController(IUpperSysService upperSysService)
        {
            _upperSysService = upperSysService;
        }

        /// <summary>
        /// 查询指定RCS的服务信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<WebApiCallBack> QueryRcsServiceAsync(int id)
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _upperSysService.QueryUppserSysAsync(id);
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "上位服务获取失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }
        /// <summary>
        /// 查询所有RCS服务信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> QueryAllRcsServiceAsync()
        {
            var result = new WebApiCallBack();
            var dtoInfos = await _upperSysService.QueryAllUppserSysAsync();
            if (dtoInfos is null)
            {
                result.status = false;
                result.msg = "获取所有上位服务失败";
                return result;
            }
            result.data = dtoInfos;
            return result;
        }
        /// <summary>
        /// 删除指定的RCS服务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<WebApiCallBack> DeleteRcsServiceAsync(int id)
        {
            var result = new WebApiCallBack();
            result.status = await _upperSysService.DeleteUppserSys(id);
            result.msg = result.status ? "删除成功" : "删除失败";
            return result;
        }
        /// <summary>
        /// 创建RCS服务信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> CreateRcsServiceAsync([FromBody] CreatUpperSysDto dto)
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _upperSysService.CreateUppserSysAsync(dto);
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "创建所有上位服务失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }
        /// <summary>
        /// 更新RCS服务信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> UpdateRcsServiceAsync([FromBody] UpdateUpperSysDto dto)
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _upperSysService.UpdateUppserSysAsync(dto);
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "更新指定上位服务失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }
        /// <summary>
        /// 查询使用中的上位服务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> QueryEffectiveUpperSysAsync()
        {
            var result = new WebApiCallBack();
            var dtoInfo = await _upperSysService.QueryEffectiveUpperSysAsync();
            if (dtoInfo is null)
            {
                result.status = false;
                result.msg = "获取有效上位服务失败";
                return result;
            }
            result.data = dtoInfo;
            return result;
        }

    }
}
